<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>Document</title>
	</head>
	<body>
		<script type="text/javascript">
			//扩展运算符
			function add(x,y){
				return x+y;
			}
			
			const numbers=[4,38];
			let result=add(...numbers);
			console.log(result);//42
			
			//使用Array.from方法
			let arrayLike={
				'0':'a',
				'1':'b',
				'2':'c',
				length:3
			};
			//ES5的写法
			var arr1 = [].slice.call(arrayLike);//['a','b','c']
			
			//ES6的写法
			let arr2 = Array.from(arrayLike);//['a','b','c']
			
			//转化NodeList集合
			//NodeList对象
			let ps=document.querySelectorAll('p');
			let ps2=Array.from(ps);
			console.log(ps2);
			
			//Array构造函数的问题
			let a=Array();//[]
			let b=Array(3);//[空属性 X 3]
			let c=Array(3,11,8);//[3,11,8]
			
			console.log(a);	//Array[0]
			console.log(b);	//Array[3]
			console.log(b);	//Array[3]
			
			//使用Array.of方法构造数组
			let a=Array.of()//[]
			let b=Array.of(undefined)//[undefined]
			let c=Array.of(3)//[3]
			let d=Array.of(1,2,3)//[1,2,3]
			
			console.log(a);
			console.log(b);
			console.log(c);
			console.log(d);
			
			//数组实例方法
			//1.find方法
			let arr = Array.of(2,4,6,8);
			console.log(arr.find(item =>item>2));//4
			
			//2.findIndex方法
			let arr2=Array.of(1,2,1,3);
			console.log(arr.findIndex(item=>item==2));//1
			//数组空位处理为undefined
			console.log([,1].findIndex(n=>true));//0
			
			//3.fill方法
			let arr = Array.of(1,2,3,4);
			//参数1: 用来填充的值
			//参数2: 被填充的起始索引
			//参数3(可选): 被填充的结束索引，默认为数组末尾
			console.log(arr.fill(0,1,2));//[1,0,3,4]
		</script>
	</body>
</html>